package com.jcsz.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @className: OrderConfirmVo
 * @author: 一把Po吉他
 * @date: 2022/11/12 13:08
 * @version: 1.0
 **/
public class OrderConfirmVo {
    //收货地址
    @Setter
    @Getter
    private List<MemberAddressVo> address;
    //购物项
    @Getter
    @Setter
    private List<OrderItemVo> item;
    //积分信息
    @Getter
    @Setter
    private Integer integration;
    //总金额
    private BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal aomunt = new BigDecimal("0");
        if (item != null) {
            for (OrderItemVo orderItemVo : item) {
                aomunt = aomunt.add(orderItemVo.getPrice().multiply(new BigDecimal(orderItemVo.getCount())));
            }
        }
        return aomunt;
    }

    //是否有库存
    @Getter
    @Setter
    private Map<Long, Boolean> stocks;
    //应付价格
    private BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        BigDecimal aomunt = new BigDecimal("0");
        if (item != null) {
            for (OrderItemVo orderItemVo : item) {
                aomunt = aomunt.add(orderItemVo.getPrice().multiply(new BigDecimal(orderItemVo.getCount())));
            }
        }
        return aomunt;

    }

    //商品购物项数量
    private Integer count;

    public Integer getCount() {
        int i = 0;
        if (item != null) {
            for (OrderItemVo orderItemVo : item) {
                i += orderItemVo.getCount();
            }
        }
        return i;
    }

    /**
     * 接口幂等性token
     */
    @Getter
    @Setter
    private String orderToken;
}
